//
//  SizeFit.swift
//  CodingTest
//
//  Created by LYPC on 2021/11/18.
//

import UIKit

public protocol SizeTransform {
    var cgFloat: CGFloat    { get }
    var round: CGFloat      { get }
    var ceil: CGFloat       { get }
    var floor: CGFloat      { get }
    var abs: CGFloat        { get }
    var fitR: CGFloat       { get }
    var fitC: CGFloat       { get }
    var fitF: CGFloat       { get }
    var fitT: CGFloat       { get }
    
    var double: Double      { get }
    var float: Float        { get }
    var half: CGFloat       { get }
    var int: Int            { get }
}

public extension SizeTransform {
    
    var round: CGFloat { return CGFloat(roundf(float)) }
    var ceil: CGFloat  { return CGFloat(ceilf(float)) }
    var floor: CGFloat { return CGFloat(floorf(float)) }
    var abs: CGFloat { return CGFloat(fabsf(float)) }
    var fitR: CGFloat
    { return (ScreenSize.shared.screenWidthRatio * cgFloat).round }
    var fitC: CGFloat
    { return (ScreenSize.shared.screenWidthRatio * cgFloat).ceil }
    var fitF: CGFloat
    { return (ScreenSize.shared.screenWidthRatio * cgFloat).floor }
    var fitT: CGFloat
    { return (ScreenSize.shared.screenWidthRatio * cgFloat) }
    
    var double: Double { return Double(cgFloat) }
    var float: Float   { return Float(cgFloat) }
    var half: CGFloat  { return cgFloat * 0.5 }
    var int: Int       { return Int(float) }
}

extension Int: SizeTransform {
    public var cgFloat: CGFloat { return CGFloat(self) }
    public var int: Int         { return self }
}
extension CGFloat: SizeTransform {
    public var cgFloat: CGFloat { return self }
}
extension Double: SizeTransform {
    public var cgFloat: CGFloat { return CGFloat(self) }
    public var double: Double   { return self }
}
extension Float: SizeTransform {
    public var cgFloat: CGFloat { return CGFloat(self) }
    public var float: Float     { return self }
}
